﻿using System;
using System.ComponentModel;
using System.Globalization;

namespace TeamDeployer.TeamFoundation.Build.Workflow.CustomTypes
{
    internal class DeploySpecPropertyDescriptor : PropertyDescriptor
    {
        // Fields
        private int _Index;

        private DeploySpecList _List;

        private DeploySpec _Spec;

        // Methods
        public DeploySpecPropertyDescriptor(DeploySpecList specList, int index)
        : base("Index" + index.ToString(CultureInfo.InvariantCulture), new Attribute[0])
        {
            this._List = specList;
            this._Index = index;
            this._Spec = this._List[this._Index];
        }

        // Properties
        public override Type ComponentType
        {
            get
            {
                return this.PropertyType;
            }
        }
        public override string DisplayName
        {
            get
            {
                return string.Format("{0} Deploy Package Spec", new object[] { this._Index + 1 });
            }
        }
        public override bool IsReadOnly
        {
            get
            {
                return false;
            }
        }
        public override Type PropertyType
        {
            get
            {
                return this._Spec.GetType();
            }
        }

        public override bool CanResetValue(object component)
        {
            return false;
        }

        public override object GetValue(object component)
        {
            return this._Spec;
        }

        public override void ResetValue(object component)
        {
            throw new NotImplementedException();
        }

        public override void SetValue(object component, object value)
        {
            this._Spec = (DeploySpec)value;
            this._List[this._Index] = this._Spec;
        }

        public override bool ShouldSerializeValue(object component)
        {
            return false;
        }
    }
}
